<script>
import { rlNotice } from "@/http/api";
export default {
  components: {},
  name: "",
  data() {
    return {
      resDate: [],
      showCont: false,
    };
  },
  computed: {},
  props: {},
  setup() {},
  methods: {
    getTime(time) {
      const y = time.getFullYear();
      const m =
        time.getMonth() < 9 ? `0${time.getMonth() + 1}` : time.getMonth() + 1;
      const d = time.getDate() < 10 ? `0${time.getDate()}` : time.getDate();

      const str = `${y}-${m}-${d}`;
      return str;
    },
    setCheck(data) {
      let nowDay = this.getTime(new Date());
      if (this.resDate && this.resDate.length > 0) {
        for (let item of this.resDate) {
          if (item.date.includes(data.day)) {
            return "dayYuan dayActive";
          } else if (nowDay === data.day) {
            return "dayYuan dayActiveOp";
          } else {
            return "dayYuan";
          }
        }
      } else {
        return "dayYuan";
      }
    },
    showTip(data) {
      if (this.resDate && this.resDate.length > 0) {
        for (let item of this.resDate) {
          if (item.date.includes(data.day)) {
            return item;
          } else {
            return false;
          }
        }
      } else {
        return false;
      }
    },
    interFn(item) {
      console.log(this.$route.path);
      if (this.$route.path == "/bootInviteDetail") {
        this.$emit("inter", item.id);
      } else {
        this.$router.push({
          path: "/bootInviteDetail",
          query: { id: item.id },
        });
      }
    },
    talkFn(item) {
      this.$router.push({ path: "/salaPublicDetail", query: { id: item.id } });
    },
    getNowNum(data) {
      let nowDate = this.getTime(new Date());
      let result = 0;
      if (data.length > 0) {
        let nowArr = data.filter((item) => {
          return item.date === nowDate;
        });
        if (nowArr.length > 0) {
          result = nowArr[0].interArr.length + nowArr[0].talkArr.length;
        }
      }
      this.$emit("getNum", result);
    },
    getDateFn() {
      rlNotice().then((res) => {
        if (res.data.code == 1) {
          this.resDate = res.data.data;
          this.showCont = true;
          this.getNowNum(res.data.data);
        }
      });
    },
  },
  mounted() {},
  created() {
    this.getDateFn();
  },
};
</script>
<template>
  <div class="calendarCont" v-if="showCont">
    <div class="calendarTitle">日历待办事项</div>
    <el-calendar>
      <template #date-cell="{ data }">
        <div class="dayItem">
          <div v-if="showTip(data) === false" :class="setCheck(data)">
            {{ data.day.split("-")[2] }}
          </div>
          <el-popover
            v-if="showTip(data) !== false"
            placement="bottom"
            :width="300"
            trigger="hover"
          >
            <template #reference>
              <div :class="setCheck(data)">
                {{ data.day.split("-")[2] }}
              </div>
            </template>
            <div class="dateTip">
              <div class="dateTipItem" v-if="showTip(data).talkArr.length > 0">
                <div class="dateTipItemName">沟通提醒</div>
                <div
                  class="dateTipItemDes"
                  :key="index"
                  v-for="(item, index) in showTip(data).talkArr"
                >
                  船员<span class="blueText linkText" @click="talkFn(item)"
                    >《{{ item.cont }}》</span
                  >待沟通
                </div>
              </div>
              <div class="dateTipItem" v-if="showTip(data).interArr.length > 0">
                <div class="dateTipItemName">面试提醒</div>
                <div
                  class="dateTipItemDes"
                  :key="index"
                  v-for="(item, index) in showTip(data).interArr"
                >
                  船员<span class="linkText_" @click="interFn(item)"
                    >《{{ item.cont }}》</span
                  >待面试
                </div>
              </div>
            </div>
          </el-popover>
        </div>
      </template>
    </el-calendar>
  </div>
</template>
<style scoped lang="less">
.calendarCont {
  padding: 15px 20px;
  box-sizing: border-box;
  .calendarTitle {
    text-align: center;
    // color: #fff;
    font-size: 15px;
    font-weight: bold;
    margin-bottom: 15px;
  }
  .dayItem {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    .dayYuan {
      width: 34px;
      text-align: center;
      line-height: 34px;
      height: 34px;
      border-radius: 50%;
    }
    .dayActive {
      background-color: #4b58dc;
      color: #fff;
    }
    .dayActiveOp {
      background-color: #b0b7ff;
      color: #fff;
    }
  }
}
</style>
<style>
.el-calendar-table .el-calendar-day {
  height: 50px;
  padding: 0;
}
.el-calendar {
  border-radius: 10px;
  overflow: hidden;
}
.el-calendar {
  --el-calendar-border: none;
  --el-calendar-selected-bg-color: #ffffff;
}
.el-calendar .el-button--small {
  height: 34px;
  color: #666;
  padding: 5px 15px;
}
</style>
